const categoryService = require('../services/categoryService')

const categoryController = {
  async getCategory(req, res, next) {
    try {
      let data = await categoryService.getCategory()
      res.send({
        code: 200,
        msg: 'ok',
        data,
      })
    } catch (error) {
      res.send({
        code: 400,
        msg: error.message,
      })
    }
  },
  async getCarId(req, res, next) {
    try {
      let data = await categoryService.getCarId()
      res.send({
        code: 200,
        msg: 'ok',
        data,
      })
    } catch (error) {
      res.send({
        code: 400,
        msg: error.message,
      })
    }
  },
  async addCategory(req, res, next) {
    try {
      let data = await categoryService.addCategory(req.body.name)
      res.send({
        code: 200,
        msg: 'ok',
        data,
      })
    } catch (error) {
      res.send({
        code: 400,
        msg: error.message,
      })
    }
  },
  async updateCategory(req, res, next) {
    try {
      let data = await categoryService.updateCategory(req.body)
      res.send({
        code: 200,
        msg: 'ok',
        data,
      })
    } catch (error) {
      res.send({
        code: 400,
        msg: error.message,
      })
    }
  },
  async deleteCategory(req, res, next) {
    try {
      let data = await categoryService.deleteCategory(req.body.id)
      res.send({
        code: 200,
        msg: 'ok',
        data,
      })
    } catch (error) {
      res.send({
        code: 400,
        msg: error.message,
      })
    }
  },
}

module.exports = categoryController
